package org.zxp.javacheck.enumtest;

/**
 * @program: effectiveJava
 * @description: enum用法2 绑定int
 * @author: X-Pacific zhang
 * @create: 2019-08-19 13:57
 **/
//public enum Color implements Behaviour{ //也可以实现接口 来定义枚举的统一抽象动作
public enum  Color2 {
    RED("红色", 5), GREEN("绿色", 6), BLANK("白色", 7), YELLO("黄色", 8);
    // 成员变量
    private String name;
    private int index;
    // 构造方法
    private Color2(String name, int index) {
        this.name = name;
        this.index = index;
    }
    // 普通方法
    public static String getName(int index) {
        for (Color2 c : Color2.values()) {
            if (c.getIndex() == index) {
                return c.name;
            }
        }
        return null;
    }
    // get set 方法
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getIndex() {
        return index;
    }
    public void setIndex(int index) {
        this.index = index;
    }

    //覆盖方法
    @Override
    public String toString() {
        return this.index+"_"+this.name;
    }
}
